﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace XmlDSigEx
{
    class DereferencerFactory
    {
        private static List<IDereferencerProvider> _Providers = new List<IDereferencerProvider>();

        static DereferencerFactory()
        {
            // Default configuration.
            AddProvider(new DereferencerProvider());
        }

        public static void AddProvider(IDereferencerProvider Provider)
        {
            _Providers.Insert(0, Provider);
        }

        public static IUriDereferencer GetDereferencer(string uri)
        {
            foreach (IDereferencerProvider Provider in _Providers)
            {
                if (Provider.CanHandle(uri))
                    return Provider.GetDereferencer(uri);
            }
            throw new UnknownAlgorithmException(string.Format("No dereferencer was registered for the uri {0}.", uri));
        }
    }
}
